package com.lagou.ipersistence.reflection;

import com.lagou.ipersistence.reflection.invoker.Invoker;

/**
 * @author Yan Jiahong
 * Created on 2020/11/17
 */
public class MetaClass {
    private final ReflectorFactory reflectorFactory;
    private final Reflector reflector;
    
    public MetaClass(Class<?> type, ReflectorFactory reflectorFactory) {
        this.reflectorFactory = reflectorFactory;
        this.reflector = reflectorFactory.findClass(type);
    }
    
    public static MetaClass forClass(Class<?> type, ReflectorFactory reflectorFactory) {
        return new MetaClass(type, reflectorFactory);
    }
    
    /**
     * 判断这个类是否拥有这个方法
     *
     * @param name 属性名, 暂时不支持user.order.id这种嵌套属性
     */
    public boolean hasGetter(String name) {
        // 暂时不支持嵌套对象的处理
        return reflector.hasGetter(name);
    }
    
    public Class<?> getGetterType(String name) {
        return reflector.getGetterType(name);
    }
    
    public Class<?> getSetterType(String name) {
        return reflector.getGetterType(name);
    }
    
    public Invoker getSetInvoker(String name) {
        return reflector.getSetInvoker(name);
    }
    
    public Invoker getGetInvoker(String name) {
        return reflector.getGetInvoker(name);
    }
}
